<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改合同')"/>
    <th:block th:include="include :: datetimepicker-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-contract-edit" th:object="${wbContract}">
        <input name="id" th:field="*{id}" type="hidden">
        <input id="treeId" name="deptId" th:value="*{deptId}" type="hidden"/>
        <div class="form-group">
            <label class="col-sm-3 control-label">合同名称：</label>
            <div class="col-sm-8">
                <input class="form-control" name="contractName" th:field="*{contractName}" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">单位名称：</label>
            <div class="col-sm-8">
                <input class="form-control" name="companyName" th:field="*{companyName}" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">合同编号：</label>
            <div class="col-sm-8">
                <input class="form-control" name="contractNumber" th:field="*{contractNumber}" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">合同价值：</label>
            <div class="col-sm-8">
                <input class="form-control" name="contractValue" th:value="*{contractValue}" type="number">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label" for="treeName">经办部门：</label>
            <div class="col-sm-8">
                <div class="input-group">
                    <input class="form-control" id="treeName" onclick="selectDeptTree();"
                           readonly th:value="*{deptName}" type="text">
                    <span class="input-group-addon"><i class="fa fa-search"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">经办人：</label>
            <div class="col-sm-8">
                <input class="form-control" name="contractCustomerManager" th:field="*{contractCustomerManager}"
                       type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">经办人号码：</label>
            <div class="col-sm-8">
                <input class="form-control" name="contractCustomerManager" th:field="*{operatorPhoneNumber}"
                       type="number">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">开始日期：</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <input class="form-control"
                           name="contractStartDate" placeholder="yyyy-MM-dd"
                           th:value="${#dates.format(wbContract.contractStartDate, 'yyyy-MM-dd')}" type="text">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">结束日期：</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <input class="form-control" name="contractEndDate"
                           placeholder="yyyy-MM-dd" th:value="${#dates.format(wbContract.contractEndDate, 'yyyy-MM-dd')}" type="text">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">状态：</label>
            <div class="col-sm-8">
                <select class="form-control m-b" name="contractStatus" th:with="type=${@dict.getType('wb_contract_status')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{contractStatus}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">用途：</label>
            <div class="col-sm-8">
                <textarea class="form-control" name="contractPurpose">[[*{contractPurpose}]]</textarea>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>
<script th:inline="javascript">
    var prefix = ctx + "workbench/contract";
    $("#form-contract-edit").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-contract-edit').serialize());
        }
    }

    $("input[name='contractStartDate']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    $("input[name='contractEndDate']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    /*部门管理-新增-选择父部门树*/
    function selectDeptTree() {
        let options = {
            title: '部门选择',
            width: "380",
            url: "/system/dept/selectDeptTree/" + $("#treeId").val(),
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero) {
        let body = layer.getChildFrame('body', index);
        $("#treeId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        //检测部门类型框是否可用
        layer.close(index);
    }
</script>
</body>
</html>
